import { StaffFees } from './staffFee';
let _StaffFees = StaffFees;
/**
 * 拷贝下面两行到 mock/index.js中,即可支持客户端虚拟数据、免服务端连接
 * import StaffFeeMock from './mk/mng/computed/day/staffFeeMock';
 * StaffFeeMock.bootstrap(mock);
 */
export default {
  /**
   * mock bootstrap
   */
  bootstrap(mock) {    
  
    //获取列表 模糊查询、根据关键字查询
    mock.onGet('/mk/mng/computed/day/staffFee/listKey').reply(config => {
      let params = config.params;
      let mockStaffFees = _StaffFees.filter(staffFee => {
      	if(params.mkStaff||params.mkStaff==''){ if( staffFee.mkStaff.indexOf(params.mkStaff)>=0) return true;}
      	if(params.orderTotalFee||params.orderTotalFee==''){ if( staffFee.orderTotalFee.indexOf(params.orderTotalFee)>=0) return true;}
      	if(params.orderTotalAmount||params.orderTotalAmount==''){ if( staffFee.orderTotalAmount.indexOf(params.orderTotalAmount)>=0) return true;}
      	if(params.orderActPayAmount||params.orderActPayAmount==''){ if( staffFee.orderActPayAmount.indexOf(params.orderActPayAmount)>=0) return true;}
      	if(params.orderReduceAmount||params.orderReduceAmount==''){ if( staffFee.orderReduceAmount.indexOf(params.orderReduceAmount)>=0) return true;}
      	if(params.custCount||params.custCount==''){ if( staffFee.custCount.indexOf(params.custCount)>=0) return true;}
      	if(params.bizDate||params.bizDate==''){ if( staffFee.bizDate.indexOf(params.bizDate)>=0) return true;}
      	if(params.staffFee||params.staffFee==''){ if( staffFee.staffFee.indexOf(params.staffFee)>=0) return true;}
      	if(params.startComputedDate||params.startComputedDate==''){ if( staffFee.startComputedDate.indexOf(params.startComputedDate)>=0) return true;}
      	if(params.id||params.id==''){ if( staffFee.id.indexOf(params.id)>=0) return true;}
      	if(params.mkStaffName||params.mkStaffName==''){ if( staffFee.mkStaffName.indexOf(params.mkStaffName)>=0) return true;}
      	if(params.computedStatus||params.computedStatus==''){ if( staffFee.computedStatus.indexOf(params.computedStatus)>=0) return true;}
      	if(params.orderCount||params.orderCount==''){ if( staffFee.orderCount.indexOf(params.orderCount)>=0) return true;}
        return false;
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            data: mockStaffFees
          }]);
        }, 1000);
      });
    });
    
    

    //获取列表（分页/不分页）
    mock.onGet('/mk/mng/computed/day/staffFee/list').reply(config => {
      let params = config.params;
      let mockStaffFees = _StaffFees.filter(staffFee => {
      	var isTrue=false;
      	if(params.mkStaff||params.mkStaff==''){if(staffFee.mkStaff.indexOf(params.mkStaff)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.orderTotalFee||params.orderTotalFee==''){if(staffFee.orderTotalFee.indexOf(params.orderTotalFee)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.orderTotalAmount||params.orderTotalAmount==''){if(staffFee.orderTotalAmount.indexOf(params.orderTotalAmount)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.orderActPayAmount||params.orderActPayAmount==''){if(staffFee.orderActPayAmount.indexOf(params.orderActPayAmount)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.orderReduceAmount||params.orderReduceAmount==''){if(staffFee.orderReduceAmount.indexOf(params.orderReduceAmount)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.custCount||params.custCount==''){if(staffFee.custCount.indexOf(params.custCount)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.bizDate||params.bizDate==''){if(staffFee.bizDate.indexOf(params.bizDate)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.staffFee||params.staffFee==''){if(staffFee.staffFee.indexOf(params.staffFee)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.startComputedDate||params.startComputedDate==''){if(staffFee.startComputedDate.indexOf(params.startComputedDate)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.id||params.id==''){if(staffFee.id.indexOf(params.id)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.mkStaffName||params.mkStaffName==''){if(staffFee.mkStaffName.indexOf(params.mkStaffName)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.computedStatus||params.computedStatus==''){if(staffFee.computedStatus.indexOf(params.computedStatus)>=0){isTrue=true;}else{isTrue=false;}}
      	if(params.orderCount||params.orderCount==''){if(staffFee.orderCount.indexOf(params.orderCount)>=0){isTrue=true;}else{isTrue=false;}}
      	return isTrue;
	  });
      if(!config.params.currentPage){ 
	      return new Promise((resolve, reject) => {
	        setTimeout(() => {
	          resolve([200, {
	            data: mockStaffFees
	          }]);
	        }, 1000);
	      });
      }
    
      let {pageSize,currentPage, total} = config.params;
      total = mockStaffFees.length;
      mockStaffFees = mockStaffFees.filter((staffFee, index) => index < pageSize * currentPage && index >= pageSize * (currentPage - 1));
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            pageInfo: {
            	total:total
            },
            data: mockStaffFees,
            tips:{
            	isOk:true,
            	msg:'查询成功'
            }
          }]);
        }, 1000);
      });
    });

    //删除
    mock.onPost('/mk/mng/computed/day/staffFee/del').reply(config => {
      var params = JSON.parse( config.data );
      let {  id  } = params;
      _StaffFees = _StaffFees.filter(staffFee => staffFee.id !== id);
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'删除成功'
            }
          }]);
        }, 500);
      });
    });

    //批量删除
    mock.onPost('/mk/mng/computed/day/staffFee/batchDel').reply(config => {
      var params = JSON.parse( config.data );
      _StaffFees = _StaffFees.filter(staffFee => !params.includes(staffFee.id));
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
           tips:{
            	isOk:true,
            	msg:'删除成功'
            }
          }]);
        }, 500);
      });
    });

    //编辑
    mock.onPost('/mk/mng/computed/day/staffFee/edit').reply(config => {
      var params = JSON.parse( config.data );
      let { mkStaff,orderTotalFee,orderTotalAmount,orderActPayAmount,orderReduceAmount,custCount,bizDate,staffFee,startComputedDate,id,mkStaffName,computedStatus,orderCount } = params;
      _StaffFees.some(staffFee => {
        if (staffFee.id === id) {
			staffFee.mkStaff = mkStaff;
			staffFee.orderTotalFee = orderTotalFee;
			staffFee.orderTotalAmount = orderTotalAmount;
			staffFee.orderActPayAmount = orderActPayAmount;
			staffFee.orderReduceAmount = orderReduceAmount;
			staffFee.custCount = custCount;
			staffFee.bizDate = bizDate;
			staffFee.staffFee = staffFee;
			staffFee.startComputedDate = startComputedDate;
			staffFee.id = id;
			staffFee.mkStaffName = mkStaffName;
			staffFee.computedStatus = computedStatus;
			staffFee.orderCount = orderCount
          return true;
        }
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'编辑成功'
            }
          }]);
        }, 500);
      });
    });

    //新增
    mock.onPost('/mk/mng/computed/day/staffFee/add').reply(config => {
      var params = JSON.parse( config.data );
      let { mkStaff,orderTotalFee,orderTotalAmount,orderActPayAmount,orderReduceAmount,custCount,bizDate,staffFee,startComputedDate,id,mkStaffName,computedStatus,orderCount } = params;
      _StaffFees.push({
		mkStaff:mkStaff,
		orderTotalFee:orderTotalFee,
		orderTotalAmount:orderTotalAmount,
		orderActPayAmount:orderActPayAmount,
		orderReduceAmount:orderReduceAmount,
		custCount:custCount,
		bizDate:bizDate,
		staffFee:staffFee,
		startComputedDate:startComputedDate,
		id:id,
		mkStaffName:mkStaffName,
		computedStatus:computedStatus,
		orderCount:orderCount
      });
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve([200, {
            tips:{
            	isOk:true,
            	msg:'新增成功'
            }
          }]);
        }, 500);
      });
    });

  }
};